Skip to content

fix(apiutil): normalize server URL before appending /api/v1#72

Merged
electather merged 2 commits intomainfrom
fix/normalize-server-url
Mar 16, 2026
Merged

fix(apiutil): normalize server URL before appending /api/v1#72
electather merged 2 commits intomainfrom
fix/normalize-server-url

Conversation

@electather
Copy link
Owner

Summary

Fixes a bug where https://host/api/v1/ (trailing slash after /api/v1) was incorrectly expanded to https://host/api/v1/api/v1 because strings.TrimSuffix only removed a single trailing slash before the suffix check.

Closes #62

Changes

  • Extract NormalizeServerURL(raw string) string that trims all trailing slashes with strings.TrimRight before the /api/v1 suffix check
  • Replace the inline normalization in NewAPIClientWithKeyAndTransport with a call to NormalizeServerURL
  • Add table-driven tests covering bare host, single/multiple trailing slashes, already-correct URL, trailing slash on /api/v1, empty string, and slash-only input

Test plan

  • go test -v ./... passes
  • go fmt ./... produces no diff
  • go build succeeds

Checklist

  • New tests added for new behaviour
  • Documentation updated (README, command --help, comments)
  • No unrelated changes included

Extract NormalizeServerURL to trim all trailing slashes before the
suffix check. The old TrimSuffix approach only removed one slash, so
https://host/api/v1/ would incorrectly become https://host/api/v1/api/v1.

Closes #62
@electather electather merged commit 8aba3a7 into main Mar 16, 2026
2 checks passed
@electather electather deleted the fix/normalize-server-url branch March 16, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Normalize configured server URL before appending /api/v1

1 participant